<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="java.util.*,com.epam.tcs.actions.*,com.epam.tcs.dao.hibernate.entities.*"%>
<%@ include file="../template/header.jsp" %>
<%@ include file="../template/left_menu_alt.jsp" %>
<div id="content">
		<div id="breadcrumbs">
		<c:if test="${requestScope.breadcrumbs != null}">
			<c:set var="i" value="0"/>
			<c:forEach items="${requestScope.breadcrumbs}" var="bc">
				<a href="${pageContext.request.contextPath}${bc.getUrl()}">${bc.getCaption()}</a>		
			</c:forEach>
		</c:if>
	</div>
	<span style="color: green;">
		${requestScope.message}
	</span>
	<c:if test="${sessionScope.listThemes != null}">		
	<form name="theme_form" method=post action="">
	<table>	
		<tr>
			<th><input type="checkbox" onclick="checkAll()" name="theme_check"/></th>
			<th></th>
			<th>Название</th>
			<th>Кол-во часов</th>	
			<th>Описание</th>				
		</tr>
		<c:forEach items="${sessionScope.listThemes}" var="t">
			<tr>
				<td><input type="checkbox" name="theme_check_${t.theme_id}"/></td>
				<td><a href="${pageContext.request.contextPath}/tcs/theme/edit?theme_id=${t.theme_id}"><span class="ui-icon ui-icon-pencil"></span></a></td>
				<td>${t.name}</td>
				<td>${t.hours}</td>				
				<td>${t.description}</td>
			</tr>
		</c:forEach>
		</table>
	</form>
	</c:if>
</div>
<script type="text/javascript">
$(function() {
	$('#del_theme').bind('click', function(){
		deleteThemes();
	});
	$('#add_theme').bind('click', function(){
		addTheme();
	});
});
function addTheme() {
	window.location = "${pageContext.request.contextPath}/tcs/theme/add";
}
function checkAll() {
	if ($("input[name = theme_check]").attr("checked")) {
		$("input[name ^= theme_check]").each(
			function() {
				$(this).attr("checked",true);
			}
		);
	} else {
		$("input[name ^= theme_check]").each(
				function() {
					$(this).attr("checked",false);
				}
			);
	}
}
function deleteThemes() {
	var themes = [];
	$("input[name ^= theme_check]:checked").each(
		function(index) {
			themes[index] = $(this).attr("name");
		}
	);
	$("form[name = theme_form]").attr("action", "${pageContext.request.contextPath}/tcs/theme/del");
	$("form[name = theme_form]").submit();	
}
</script>
<%@ include file="../template/footer.jsp" %>